package cn.mazexal.examapi.generateData;

import cn.mazexal.examapi.dataware.CardMenuMapper;
import cn.mazexal.examapi.models.db.CardMenuDO;
import cn.mazexal.examapi.utils.RandomUtils;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Mazexal
 * Date: 2025/5/12
 */
@SpringBootTest
public class ConfigDataWithService {

    @Resource
    private CardMenuMapper cardMenuMapper;


    @Test
    public void generateCardMenuData() {
        Long now = System.currentTimeMillis();
        List<CardMenuDO> res = new ArrayList<>();
        for (long i = 0; i < 100; i++) {
            int parentId = RandomUtils.getRandomNum(0, (int) i);
            res.add(buildWithArgs(i, (long) parentId, "菜单" + i, RandomUtils.getRandomNum(1, 2), 101L, now));
        }

        cardMenuMapper.insert(res);
    }

    CardMenuDO buildWithArgs(Long id, Long parentId, String name, Integer menuType, Long examBankId, Long createTime) {
        CardMenuDO cardMenuDO = new CardMenuDO();
        cardMenuDO.setId(id);
        cardMenuDO.setParentId(parentId);
        cardMenuDO.setName(name);
        cardMenuDO.setMenuType(menuType);
        cardMenuDO.setCreateTime(createTime);
        cardMenuDO.setUpdateTime(createTime);
        cardMenuDO.setExamBankId(examBankId);
        cardMenuDO.setIsDel(0);
        return cardMenuDO;
    }
}
